<template>
  <a-card :bordered="false" :style="{ marginTop: '12px',height:'670px' }">
    <span slot="title"> <a-icon type="tags" style="color:#3393FC;margin-right: 5px" theme="filled"/>新闻动态</span>
    <a slot="extra" @click="loadMore('A01')">更多</a>
    <!--展示新闻动态信息-->
    <template v-if="newInfos.length>0">
      <a-list itemLayout="horizontal" :dataSource="newInfos" class="tableList">
        <a-list-item @click="showDetail(item)" slot="renderItem" :key="index" slot-scope="item, index" style="margin:10px 0px" >
          <a-list-item-meta :description="item.content | contentFilter">
            <a slot="title" href="#">{{item.title}}</a>
            <img slot="avatar" :src="getAvatarView(item.imageHref)" style="width:220px;height:110px;"/>
          </a-list-item-meta>
          <template slot="actions">
            <span @click.stop="eyeClick(item)">
              <a-icon type="eye"  style="margin-right: 5px" />{{item.readTimes==0?'':item.readTimes}}
            </span>
          </template>
        </a-list-item>
      </a-list>
    </template>
    <template v-else>
      <a-empty />
    </template>
    <eoa-cms-article-reader-modal ref="readerModal"></eoa-cms-article-reader-modal>
  </a-card>

</template>

<script>
  import { WebsocketMixin } from '@/mixins/WebsocketMixin'
  import { getFileAccessHttpUrl } from '@/api/manage'
  import EoaCmsArticleReaderModal from '../../cms/modules/EoaCmsArticleReaderModal'
  import { getSiteInfo } from '@/api/api'

  export default {
    name: 'EoaCmsNewsInfo',
    mixins: [WebsocketMixin],
    components: {
      EoaCmsArticleReaderModal,
    },
    data () {
      return {
        socketUrl:'newsWebsocket',
        newInfos:this.formData,
      }
    },
    props: ['formData'],
    filters: {
      contentFilter (content ){
        // let reg1=/<().*?>/g;
        let reg2 =/<\/?.+?\/?>/g;
        content = content.replace(reg2, '').replace(new RegExp("&nbsp;","gm"), '').replace(new RegExp("&darr;","gm"), '')
        if(content.length >100){
          content= content.slice(0,100)+"......"
        }
        return content;
      }
    },
    methods: {
      loadMore(type){
        this.$router.push({ path: '/modules/eoa/cms/eoaCmsArticlePortal',query:{type:type}})
      },
      initSiteInfo () {
        var _this=this;
        getSiteInfo().then((res)=>{
          if(res.success){
            _this.newInfos=res.result.NEWS_INFO;
          }
        })
      },
      websocketOnmessage: function (e) {
        console.log("-----接收消息-------",e.data);
        //解析对象
        var data = eval("(" + e.data + ")");
        if(data.cmd == "publish"){
          //查询新闻
          this.initSiteInfo();
        }
      },
      showDetail(item){
        console.log("showDetail==>item", item);
        this.$router.push({ path: '/modules/eoa/cms/modules/eoaCmsArticleDetailModal',query : { item:item }})
      },
      getAvatarView(url){
        return getFileAccessHttpUrl(url)
      },
      eyeClick(item){
        this.$refs.readerModal.loadReader(item);
      },
    }

  }
</script>

<style scoped>

</style>